n
<template>
  <j-modal
    switchFullscreen
    :title='title'
    :width='800'
    :visible='visible'
    :maskClosable='false'
    :confirmLoading='confirmLoading'
    @cancel='handleCancel'
    cancelText='关闭'
  >
    <template slot='footer'>
      <a-button @click='handleCancel'>取消</a-button>
      <a-button v-if='!disableSubmit' :loading="confirmLoading" type='primary' @click='handleOk'>确认</a-button>
    </template>
    <a-spin :spinning='confirmLoading'>
      <a-form :form='form'>
        <a-row :gutter='24'>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品编号'>
              <a-input placeholder='请输入' :disabled='disableSubmit||isEdit' v-decorator="['productCode',validatorRules.input]" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品名称'>
              <a-input placeholder='请输入' :disabled='disableSubmit||isEdit'
                       v-decorator="['productName', validatorRules.input]" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='销售区域编号'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['salesAreaCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='销售区域'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['salesAreaName']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='条码'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['barCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='规格'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['specifications']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品分类编号'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['productClassificationCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品分类'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['productClassificationName']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产地'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['producingArea']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='助记码'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['mnemonicCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item label='图列' :labelCol='labelCol' :wrapperCol='wrapperCol '>
              <JUpload
                :disabled='disableSubmit'
                accept='.png,.jpg,.jpeg'
                v-decorator="['logo']"
                fileType='image'
                class='avatar-uploader'
                :number='1'
                text='产品图片'
                :returnUrl='true'
              />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='有效期'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['termOfValidity']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='品牌'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['brand']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='税率'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['taxRate']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='abc分类'>
              <a-select :disabled='disableSubmit' v-decorator="['abcClassify']" style='width: 100%' placeholder='请选择'>
                <a-select-option value='A'>
                  A类
                </a-select-option>
                <a-select-option value='B'>
                  B类
                </a-select-option>
                <a-select-option value='C'>
                  C类
                </a-select-option>
                <a-select-option value='S'>
                  S类
                </a-select-option>
                <a-select-option value='粽子'>
                  粽子
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='主单位名称'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['mainUnitName']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='辅单位名称'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['auxiliaryUnitName']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='单件毛重(千克)'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['grossWeight']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='单件最小毛重(千克)'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['minGrossWeight']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='单件最大毛重(千克)'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['maxGrossWeight']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='批次'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['batch']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='单位体积(立方米)'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['unitVolume']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='单位净重(千克)'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['unitNetWeight']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='是否可用'>
              <a-select :disabled='disableSubmit' v-decorator="['productReferred']" style='width: 100%'
                        placeholder='请选择'>
                <a-select-option :value='1'>
                  是
                </a-select-option>
                <a-select-option :value='0'>
                  否
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='折合系数'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['coefficient']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='物料类型'>
              <a-select :disabled='disableSubmit' v-decorator="['materialType']" style='width: 100%' placeholder='请选择'>
                <a-select-option value='1'>
                  产自品
                </a-select-option>
                <a-select-option value='2'>
                  促销物料
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='单托件'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['consignmentQuantity']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='运输类型'>
              <a-select :disabled='disableSubmit' v-decorator="['transportationType']" style='width: 100%'
                        placeholder='请选择'>
                <a-select-option value='1'>
                  速冻
                </a-select-option>
                <a-select-option value='0'>
                  常温
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='特殊标志'>
              <a-select :disabled='disableSubmit' v-decorator="['calculateFreight']" style='width: 100%'
                        placeholder='请选择'>
                <a-select-option :value='1'>
                  是
                </a-select-option>
                <a-select-option :value='0'>
                  否
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='详细描述'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['remarks']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='主辅单位换算率'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['unitConversionRate']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='比例'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['proportion']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品档次编号'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['productGradeCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品档次描述'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['productGradeDescribe']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品分类编号'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['productClassifyCode']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='产品分类描述'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['productClassifyDescribe']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='预算产品规格分类'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['normsClassify']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='预算产品分类描述'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['normsClassifyDescribe']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='物料组名称'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['materialGroupName']" />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24'>
            <a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='物料组编号'>
              <a-input placeholder='请输入' :disabled='disableSubmit' v-decorator="['materialGroupCode']" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>

    </a-spin>
  </j-modal>
</template>

<script>
import { getAction, httpAction, postAction } from '@/api/manage'
import { pick } from 'lodash'
import { PageListMixin } from '@/mixins/PageListMixin'
import JUpload from '@comp/cn-form/JUpload'

export default {
  name: 'product-modal',
  mixins: [PageListMixin],
  components: { JUpload },
  data() {
    return {
      title: '操作',
      disableSubmit: false,
      visible: false,
      model: {},
      isEdit:false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 10 },
        md: { span: 10 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
        md: { span: 14 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        input: {
          rules: [
            { required: true, message: '' }
          ]
        }
      },
      addOrUpdateUrl: '/products/cnProduct/saveOrUpdate'
    }
  },

  created() {
    // this.Dictionary()
  },
  watch: {},
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      if (this.title == '详情') {
        this.disableSubmit = false
      }
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))//表单初始化，值源于this.model
      })

    },
    close() {
      this.$emit('close')
      this.visible = false
    },

    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          let method = ''
          if (!this.model.id) {
            method = 'post'
          } else {
            method = 'post'
          }
          let formData = Object.assign({}, this.model, values)
          that.confirmLoading = true
          httpAction(this.addOrUpdateUrl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                that.close()
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              //that.close();
            })
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped>
</style>
